package com.service.Impl;


import com.pojo.dto.Message;
import com.pojo.vo.SelectVo;
import com.service.SysDictionaryService;
import com.service.SysUtilService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service("SysUtilService")
public class SysUtilServiceImpl implements SysUtilService {
    @Autowired
    SysDictionaryService sysDictionaryService;

    /**
     * 获取redis数据，查询字典中的内容，成为下拉框
     *
     * @param id
     * @param name
     * @return
     */
    @Override
    public Message<List<SelectVo>> select(Long id, String name) {
        Map<String, String> user = sysDictionaryService.getValues(name);
        List<SelectVo> list = new ArrayList<>();
        user.forEach((k, v) -> {
            SelectVo selectVo = new SelectVo();
            selectVo.setId(Long.valueOf(k));
            selectVo.setText(v);
            if (selectVo.getId() == id) {
                selectVo.setSelected(true);
            }
            list.add(selectVo);
        });
        return Message.successMessage(1L, list);
    }

    @Override
    public SelectVo selectone(Long id, String name) {
        String user = sysDictionaryService.getValue(name, id + "", "");
        SelectVo selectVo = new SelectVo();
        selectVo.setId(id);
        selectVo.setText(user);
        return selectVo;
    }
}
